﻿#region

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Net;
using BattleNET;
using System.Globalization;
using System.Diagnostics;
using System.Reflection;
#endregion

namespace DayZAntiHax
{
    public class Process : IProcess
    {
        //Declarations
        #region
        static int s_iNumPasses = 1;

        public static List<String[]> m_GuidsToBeBanned;
        public static List<String[]> m_IPsToBeBanned;
        public static List<String> m_BanExplanations;
        List<String> m_BannedGuids;
        List<String> m_BannedIPs;
        int m_iNumIPsBanned;
        int m_iNumGuidsBanned;
        String result;
        public bool m_bLastLineCR = false;
        public LogFile addmagazinecargo;
        public LogFile addbackpackcargo;
        public LogFile addweaponcargo;
        public LogFile attachto;
        public LogFile createvehicle;
        public LogFile deletevehicle;
        public LogFile mpeventhandler;
        public LogFile publicvariable;
        public LogFile publicvariableval;
        public LogFile remotecontrol;
        public LogFile remoteexec;
        public LogFile scripts;
        public LogFile selectplayer;
        public LogFile setdamage;
        public LogFile setpos;
        public LogFile setvariable;
        public LogFile setvariableval;
        public LogFile teamswitch; 
        public String banLists = "http://dayz-community-banlist.googlecode.com/git/bans/bans.txt,http://dayz-community-banlist.googlecode.com/git/bans/dwbans.txt";
        public static String banMessage = "Banned for % violation";
        public static LogFile[] logList = new LogFile[18];
        private double m_dParsingFrequency = 30; //second between log file checks for enabled scans
        private double m_dMessageFrequency = 20; //multiplier - how many parses between messages
        private double m_dBanListFrequency = 25; //multiplier - how many parses between banloads
        private double m_dFilterFrequency = 20; //multiplier - how many parses between filter updates
        public static double m_banType = 0;
        private bool m_bShouldShowMessage = true;  //Stop the spam
        private bool m_bShouldCheckForFlooding = true;
        public bool m_CBL_report = true;
        public static bool m_bShouldShowErrorMessage = true;
        private bool m_bShouldUseCBL = true;
        BattlEyeLoginCredentials m_BECredentials;
        public BattlEyeClient b;
        #endregion
        //EventHandlers
        #region
        public void Disconnected(BattlEyeDisconnectEventArgs args)
        {
            //Console.WriteLine(args.Message);
        }

        public void DumpMessage(BattlEyeMessageEventArgs args)
        {
            //Console.WriteLine(args.Message);
        }

        public BattlEyeLoginCredentials BECredentials
        {
            get
            {
                return m_BECredentials;
            }
        }

        public bool ShouldCheckForFlooding
        {
            get
            {
                return m_bShouldCheckForFlooding;
            }
        }

        public double ParsingFrequency
        {
            get
            {
                return m_dParsingFrequency;
            }
        }

        public Process()
        {
            
        }
        #endregion

        public void registerConfig()
        {
            try
            {
                FileInfo file = new FileInfo("config.cfg");
                StreamReader reader = file.OpenText();
                String line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Length != 0 && line[0] == '#')
                        continue;
                    if (line.Contains("Frequency_parsing"))
                    {
                        m_dParsingFrequency = Double.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Frequency_message"))
                    {
                        m_dMessageFrequency = Double.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Frequency_banlist"))
                    {
                        m_dBanListFrequency = Double.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Frequency_filter"))
                    {
                        m_dFilterFrequency = Double.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Flood_check"))
                    {
                        m_bShouldCheckForFlooding = Boolean.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Message_errors"))
                    {
                        m_bShouldShowErrorMessage = Boolean.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Message_show"))
                    {
                        m_bShouldShowMessage = Boolean.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Use_cbl"))
                    {
                        m_bShouldUseCBL = Boolean.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Ban_text"))
                    {
                        banMessage = line.Split('=')[1];
                    }
                    else if (line.Contains("Ban_lists"))
                    {
                        banLists = line.Split('=')[1];
                    }
                    else if (line.Contains("Ban_type"))
                    {
                        m_banType = Double.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("Ban_CBL_format"))
                    {
                        m_CBL_report = Boolean.Parse(line.Split('=')[1]);
                    }
                    else if (line.Contains("serveraddress"))
                    {
                        m_BECredentials.Host = line.Split('=')[1];
                    }
                    else if (line.Contains("serverport"))
                    {
                        m_BECredentials.Port = Convert.ToInt32(line.Split('=')[1]);
                    }
                    else if (line.Contains("serverpassword"))
                    {
                        m_BECredentials.Password = line.Split('=')[1];
                    }
                    int i;
                    for (i = 0; i < logList.Length; i++)
                    {
                        if (line.Contains(logList[i].m_FilterCfgName + "_update"))
                        {
                            logList[i].m_bFilterUpdate = Boolean.Parse(line.Split('=')[1]);
                            //                            Console.WriteLine(logList[i].m_FilterCfgName + "_update=" + logList[i].m_bFilterUpdate);
                        }
                        else if (line.Contains(logList[i].m_FilterCfgName + "_scan"))
                        {
                            logList[i].m_bFilterScan = Boolean.Parse(line.Split('=')[1]);
                            //                            Console.WriteLine(logList[i].m_FilterCfgName + "_scan=" + Boolean.Parse(line.Split('=')[1]));
                        }
                        else if (line.Contains(logList[i].m_FilterCfgName + "_url"))
                        {
                            logList[i].m_sFilterURL = line.Split('=')[1];
                            //                            Console.WriteLine(logList[i].m_FilterCfgName + "_url=" + logList[i].m_sFilterURL);
                        }
                        else if (line.Contains(logList[i].m_FilterCfgName + "_source"))
                        {
                            logList[i].m_FilterName = line.Split('=')[1];
                            //                            Console.WriteLine(logList[i].m_FilterCfgName + "_source=" + logList[i].m_FilterName);
                        }
                        else continue;
                    }
                }
                reader.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e+"     ERROR: Failed to read from config.cfg!");
                Console.WriteLine("            Make sure it is located in the same directory as the executable!");
            }
        }


        public bool Initialize()
        {
            {
                //Console window settings ant init output
                #region
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.BackgroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("                                                                               ");
                Console.WriteLine("                                  DayZ Anti-Hax                                ");
                Console.WriteLine("                      Created by James 'GreyEcho' Pizzurro                     ");
                Console.WriteLine("                      Updated by Jeff 'Muppet1856' Zellen,                     ");
                Console.WriteLine("                            Kane 'k4n30' Goldsmith and                         ");
                Console.WriteLine("                             Paul 'ScareD' Potseluev                           ");
                Console.WriteLine("                                                                               ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("                                       ========================================");
                Console.WriteLine("                                       This software makes use of the BattleNET");
                Console.WriteLine("                                       Library, under the LGPL and distributed");
                Console.WriteLine("                                       under said license. Credit to:");
                Console.WriteLine("                                       Vipeax & ziellos2k");
                Console.WriteLine("                                       https://github.com/ziellos2k/BattleNET");
                Console.WriteLine("                                       ========================================");
                Console.ForegroundColor = ConsoleColor.Yellow;
                #endregion
                // Create LogFile objects for each log file we need
                #region
                addbackpackcargo = new LogFile(10, "http://dayz-community-banlist.googlecode.com/git/filters/addbackpackcargo.txt", false, true, "addbackpackcargo.txt", "addbackpackcargo.log", "addBackpackCargo");
                addmagazinecargo = new LogFile(0, "http://dayz-community-banlist.googlecode.com/git/filters/addmagazinecargo.txt", false, true, "addmagazinecargo.txt", "addmagazinecargo.log", "addMagazineCargo");
                addweaponcargo = new LogFile(8, "http://dayz-community-banlist.googlecode.com/git/filters/addweaponcargo.txt", false, true, "addweaponcargo.txt", "addweaponcargo.log", "addWeaponCargo");
                attachto = new LogFile(7, "http://dayz-community-banlist.googlecode.com/git/filters/attachto.txt", false, true, "attachto.txt", "attachto.log", "attachTo");
                createvehicle = new LogFile(1, "http://dayz-community-banlist.googlecode.com/git/filters/createvehicle.txt", false, true, "createvehicle.txt", "createvehicle.log", "createVehicle");
                deletevehicle = new LogFile(11, "http://dayz-community-banlist.googlecode.com/git/filters/deletevehicle.txt", false, true, "deletevehicle.txt", "deletevehicle.log", "deleteVehicle");
                mpeventhandler = new LogFile(12, "http://dayz-community-banlist.googlecode.com/git/filters/mpeventhandler.txt", false, true, "mpeventhandler.txt", "mpeventhandler.log", "mpEventHandler"); 
                publicvariable = new LogFile(2, "http://dayz-community-banlist.googlecode.com/git/filters/publicvariable.txt", false, true, "publicvariable.txt", "publicvariable.log", "publicVariable");
                publicvariableval = new LogFile(9, "http://dayz-community-banlist.googlecode.com/git/filters/publicvariableval.txt", false, true, "publicvariableval.txt", "publicvariable.log", "publicVariableVal");
                remotecontrol = new LogFile(13, "http://dayz-community-banlist.googlecode.com/git/filters/remotecontrol.txt", false, true, "remotecontrol.txt", "remotecontrol.log", "remoteControl");             
                remoteexec = new LogFile(3, "http://dayz-community-banlist.googlecode.com/git/filters/remoteexec.txt", false, true, "remoteexec.txt", "remoteexec.log", "remoteExec");
                scripts = new LogFile(4, "http://dayz-community-banlist.googlecode.com/git/filters/scripts.txt", false, true, "scripts.txt", "scripts.log", "scripts");
                selectplayer = new LogFile(14, "http://dayz-community-banlist.googlecode.com/git/filters/selectplayer.txt", false, true, "selectplayer.txt", "selectplayer.log", "selectPlayer");
                setdamage = new LogFile(6, "http://dayz-community-banlist.googlecode.com/git/filters/setdamage.txt", false, true, "setdamage.txt", "setdamage.log", "setDamage");
                setpos = new LogFile(5, "http://dayz-community-banlist.googlecode.com/git/filters/setpos.txt", false, true, "setpos.txt", "setpos.log", "setPos");
                setvariable = new LogFile(15, "http://dayz-community-banlist.googlecode.com/git/filters/setvariable.txt", false, true, "setvariable.txt", "setvariable.log", "setVariable");
                setvariableval = new LogFile(16, "http://dayz-community-banlist.googlecode.com/git/filters/setvariableval.txt", false, true, "setvariableval.txt", "setvariable.log", "setVariableVal");
                teamswitch = new LogFile(17, "http://dayz-community-banlist.googlecode.com/git/filters/teamswitch.txt", false, true, "teamswitch.txt", "teamswitch.log", "teamSwitch");
                logList[0] = addmagazinecargo;
                logList[1] = createvehicle;
                logList[2] = publicvariable;
                logList[3] = remoteexec;
                logList[4] = scripts;
                logList[5] = setpos;
                logList[6] = setdamage;
                logList[7] = attachto;
                logList[8] = addweaponcargo;
                logList[9] = publicvariableval;
                logList[10] = addbackpackcargo;
                logList[11] = deletevehicle;
                logList[12] = mpeventhandler;
                logList[13] = remotecontrol;
                logList[14] = selectplayer;
                logList[15] = setvariable;
                logList[16] = setvariableval;
                logList[17] = teamswitch;
                #endregion
                //Check for updates and register filters and config
                #region
                checkForUpdates();
                registerConfig();
                for (int i = 0; i < 17; i++)
                {
                    logList[i].registerFilter();
                }
                Console.WriteLine("CBL format:  " + m_CBL_report);
                m_GuidsToBeBanned = new List<String[]>();
                m_IPsToBeBanned = new List<String[]>();
                m_BannedIPs = new List<String>();
                m_BannedGuids = new List<String>();
                m_BanExplanations = new List<String>();
                m_iNumGuidsBanned = 0;
                m_iNumIPsBanned = 0;
                return true;
                #endregion
            }
        }

        public void UpdateFiles()
        {
            try
            {
                using (var client = new WebClient())
                {
                    if (s_iNumPasses % m_dFilterFrequency == 0)
                    {
                        Console.Write("Downloading filters");
                        for (int i = 0; i < logList.Length; i++)
                        {
                            if (logList[i].m_bFilterUpdate)
                            {
                                Console.WriteLine("... " + logList[i].m_FilterName);
                                client.DownloadFile(logList[i].m_sFilterURL, logList[i].m_FilterName);
                            }
                        }
                        Console.Write("\n");
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("     WARNING: Failed to update local filters!");
            }
        }

        public void checkForUpdates()
        {           
            try
            {
                using (var client = new WebClient())
                {
                    {
                        Console.WriteLine("Checking for a newer version...");
                        result = client.DownloadString("http://dayz-antihax-continued.googlecode.com/svn/version.ver");
                        Version ver = Assembly.GetEntryAssembly().GetName().Version;
                        if (ver.ToString() != result)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("A new version, " + result + " is out!");
                            Console.WriteLine("You are using an old version, "+ver.ToString());
                            Console.WriteLine("Download it at: http://is.gd/dayzantihax !!!");
                            Console.ForegroundColor = ConsoleColor.Yellow;
                        }
                        else Console.WriteLine("Your version " + result +" is up-to-date!");
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("     WARNING: Failed to retrieve new versions.");
            }
        }

        public void FindGuidsToBan()
        {
            // Check DayZ community ban list
            #region
            try
            {
                using (var client = new WebClient())
                {
                    if (s_iNumPasses % m_dBanListFrequency == 0 && m_bShouldUseCBL)
                    {
                        Console.WriteLine("Downloading public banlists...");
                        String[] lists = banLists.Split(',');
                        foreach(string temp in lists )
                        {
                            Console.WriteLine(temp);
                            result = client.DownloadString(temp).Replace('\n', ' ');
                            String[] items = result.Split(' ');
                            foreach (String item in items)
                            {
                                try
                                {
                                    Guid.Parse(item);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }

                                if (m_GuidsToBeBanned.Contains(new String[5] { item, temp, String.Empty, String.Empty, String.Empty }))
                                    continue;

                                m_GuidsToBeBanned.Add(new String[5] { item, temp, String.Empty, String.Empty, String.Empty });
                                m_BanExplanations.Add("comm");
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("     WARNING: Failed to retrieve DayZ community ban list!");
            }
            #endregion
            //Parse log files and check for flood
            #region
            for (int i = 0; i < logList.Length; i++)
            {
                logList[i].ParseFilter();
                if (m_bShouldCheckForFlooding && (i==0 || i==7))
                    logList[i].checkForFlood();
            }
            #endregion
        }

        public void FindBannedGuids()
        {
            try
            {
                m_BannedGuids.Clear();
                String[] lines = File.ReadAllLines("bans.txt");
                if (lines[lines.Length - 1]!="\n")//this check is better then "" check
                {
                    m_bLastLineCR = true;
                }
                Guid ScrapGUID;
                foreach (String line in lines)
                {
                    String[] items = line.Split(' ');
                    if (Guid.TryParse(items[0],out ScrapGUID))
                    {
                        if (m_BannedGuids.Contains(items[0]))
                        {
                            continue;
                        }
                        m_BannedGuids.Add(items[0]);
                        continue;
                    }
                }
                lines = null;
            }
            catch (Exception)
            {
                if (m_bShouldShowErrorMessage)
                {
                    Console.WriteLine("     WARNING: Failed to read from bans.txt!");
                    Console.WriteLine("     The file may not exist as BE hasn't created it yet, you can ignore this message if");
                    Console.WriteLine("     you make sure the executable is located in your server's '/BattlEye' directory!");
                }
            }
        }

        public void FindBannedIPs()
        {
            try
            {
                m_BannedIPs.Clear();
                String[] lines = File.ReadAllLines("bans.txt");
                if (lines[lines.Length - 1] != "\n")//this check is better then "" check
                {
                    m_bLastLineCR = true;
                }
                IPAddress ScrapIP;
                foreach (String line in lines)
                {
                    String[] items = line.Split(' ');
                    if (IPAddress.TryParse(items[0], out ScrapIP))
                    {
                        if (m_BannedIPs.Contains(items[0]))
                        {
                            continue;
                        }
                        m_BannedIPs.Add(items[0]);
                        continue;
                    }
                }
                lines = null;
            }
            catch (Exception)
            {
                if (m_bShouldShowErrorMessage)
                {
                    Console.WriteLine("     WARNING: Failed to read from bans.txt!");
                    Console.WriteLine("     The file may not exist as BE hasn't created it yet, you can ignore this message if");
                    Console.WriteLine("     you make sure the executable is located in your server's '/BattlEye' directory!");
                }
            }
        }

        public void BanGuids()
        {
            try
            {
                int num = -1;
                    foreach (String[] guid in m_GuidsToBeBanned)
                    {
                        num++;
                        if (m_BannedGuids.Contains(guid[0]))
                            continue;   // guid has already been banned

                        using (StreamWriter writer = new StreamWriter("bans.txt", true))
                        {
                            if (!m_bLastLineCR)
                            {
                                writer.Write(Environment.NewLine);//this one is better then /n
                                m_bLastLineCR = true;
                            }
                            writer.WriteLine(guid[0] + " -1 DAH " + DateTime.Now.ToString("g", CultureInfo.CreateSpecificCulture("de-DE")) + " (" + guid[1] + ")");
                            writer.Close();
                        }
                        using (StreamWriter writer = new StreamWriter("DayZAntiHax.log", true))
                        {
                            if (m_CBL_report)
                            {
                                writer.WriteLine("");
                                writer.WriteLine("[Pass #" + s_iNumPasses + " ban at check " + num + "]");
                            }
                            writer.WriteLine(DateTime.Now + " - Banned " + guid[0] + " on pass #" + s_iNumPasses + " Reason:[ " + guid[1] + "] (" + guid[2] + " " + guid[3] + " " + guid[4] + ")");
                            if (m_CBL_report && m_BanExplanations[num] != "comm")
                            {
                                writer.WriteLine("*******************************************************************************************");
                                writer.WriteLine("GUID(s) affected:");
                                writer.WriteLine(guid[0]);
                                writer.WriteLine("Log excerpt(s):");
                                writer.WriteLine(m_BanExplanations[num]);
                                writer.WriteLine("Additional Info:");
                                writer.WriteLine(guid[4]);
                                writer.WriteLine("Detected by DayZ Anti-Hax");
                                writer.WriteLine("*******************************************************************************************");
                            }
                            writer.Close();
                        }
                        m_BannedGuids.Add(guid[0]);
                        m_iNumGuidsBanned++;
                    }
                    num = -1;
                }
            catch (Exception)
            {
                Console.WriteLine("     WARNING: Failed to write to bans.txt and/or DayZAntiHax.log!");
                Console.WriteLine("              Make sure the executable is located in your server's 'cfgdayz/BattlEye' directory!");
            }
        }
        public void banIPs()
        {
            try
            {
                int num = -1;
                foreach (String[] ip in m_IPsToBeBanned)
                {
                    num++;
                    if (m_BannedIPs.Contains(ip[0]))
                        continue;   // ip has already been banned

                    using (StreamWriter writer = new StreamWriter("bans.txt", true))
                    {
                        if (!m_bLastLineCR)
                        {
                            writer.Write(Environment.NewLine);//this one is better then /n
                            m_bLastLineCR = true;
                        }
                        writer.WriteLine(ip[0] + " -1 DAH " + DateTime.Now.ToString("g", CultureInfo.CreateSpecificCulture("de-DE")) + " (" + ip[1] + ")");
                        writer.Close();
                    }
                    using (StreamWriter writer = new StreamWriter("DayZAntiHax.log", true))
                    {
                        writer.WriteLine(DateTime.Now + " - Banned " + ip[0] + " on pass #" + s_iNumPasses + " Reason:[ " + ip[1] + "] (" + ip[2] + " " + ip[3] + " " + ip[4] + ")");
                        writer.Close();
                    }
                    m_BannedIPs.Add(ip[0]);
                    m_iNumIPsBanned++;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e + " Error banning IPs...");
            }
            }
        public void Flush()
        {
            m_GuidsToBeBanned.Clear();
            m_IPsToBeBanned.Clear();
            m_BanExplanations.Clear();
            m_iNumGuidsBanned = 0;
            m_iNumIPsBanned = 0;
        }
        
        public void Execute(object state)
        {
            BattlEyeClient b = new BattlEyeClient(m_BECredentials);
            b.BattlEyeMessageReceived += DumpMessage;
            b.BattlEyeDisconnected += Disconnected;
            b.ReconnectOnPacketLoss = true;
            // Check to see if should show message, if so check to see if pass number is reached to show it
            if (m_bShouldShowMessage && s_iNumPasses % m_dMessageFrequency == 0)
            {
                b.Connect();
                b.SendCommand(BattlEyeCommand.Say, "-1 This server protected by DayZ AntiHax");
                b.Disconnect();
            }
            
            Console.WriteLine(DateTime.Now + " - Starting pass #{0}...", s_iNumPasses);
            FindGuidsToBan(); // Check to see if any GUID's need banning
            if (m_GuidsToBeBanned.Count > 0) // If any bans are found in the logs or CBL
            {
                Console.WriteLine(DateTime.Now + " - Finding GUIDs to ban...");
                Console.WriteLine(DateTime.Now + " - Finding GUIDs already banned...");
                FindBannedGuids();
                Console.WriteLine(DateTime.Now + " - Banning GUIDs not already banned...");
                BanGuids();
                
                if (!(m_iNumGuidsBanned == 0))  //If there were ANY bans, load them into the server.
                {
                    b.Connect();
                    b.SendCommand(BattlEyeCommand.LoadBans);
                    b.Disconnect();
                }
            }
            Console.WriteLine(DateTime.Now + " - {0} GUIDs banned. Cleaning up...", m_iNumGuidsBanned);
            if (m_banType == 1 || m_banType == 2 && m_IPsToBeBanned.Count > 0) // If any bans are found in the logs or CBL
            {
                Console.WriteLine(DateTime.Now + " - Finding IPs already banned...");
                FindBannedIPs();
                Console.WriteLine(DateTime.Now + " - Banning IPs not already banned...");
                banIPs();

                if (!(m_iNumIPsBanned == 0))  //If there were ANY bans, load them into the server.
                {
                    b.Connect();
                    b.SendCommand(BattlEyeCommand.LoadBans);
                    b.Disconnect();
                }
            }
            Console.WriteLine(DateTime.Now + " - {0} IPs banned. Cleaning up...", m_iNumIPsBanned);
            Flush();
            Console.WriteLine(DateTime.Now + " - Pass #{0} complete.", s_iNumPasses);

            // Check for required filter updates
            if (s_iNumPasses % m_dFilterFrequency == 0)
            {
                bool UpdateFilters = false;
                for (int i = 0; i < logList.Length; i++)
                {
                    if (logList[i].m_bFilterUpdate)
                    {
                        UpdateFilters = true;
                        break;
                    }
                }
                if (UpdateFilters || logList[4].m_bFilterUpdate)
                {
                    UpdateFiles();
                    b.Connect();
                }
                try
                {
                if (logList[4].m_bFilterUpdate) //Check if scripts update is true
                {
                    b.SendCommand(BattlEyeCommand.LoadScripts); //Load new scripts filter into server
                    b.Disconnect();
                }

                    if (UpdateFilters)
                    {
                        b.SendCommand(BattlEyeCommand.loadEvents); //Load new filters into server
                        b.Disconnect();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
            s_iNumPasses++;
        }
    }
}